<?php

ptaste();

require_once(dirname(__FILE__)."/classes.php");


class JEngStdAuth extends JEngAuth
{
  public function __construct($site,$logger=null)
  {
    parent::__construct($site,$logger);
  }

  public function authenticate()
  {
	$res=false;
	if (isset($_COOKIE['tt_sess']))
	{
		$uxs=$_COOKIE['tt_sess'];
		$res=$this->site()->common_db()->queryf("SELECT id,name,fullname,parent,rights,email,status FROM users WHERE is_group=0 AND blocked=0 AND active_code='%s';",$uxs);
	}
	if (!$res) return false;
	if ($res->rows()!=1) return false;
	$rw=$res->anext();
	$r2=$this->site()->common_db()->queryf("SELECT id,name,rights FROM users WHERE id=%d AND blocked=0 AND is_group=1;",$rw['parent']);
	if (!$r2) return false;
	if ($r2->rows()!=1) return false;
	$rw2=$r2->anext();
	$usr=new JEngUser($this->site());
	//set_user($id,$name,$fullname,$group,$gid,$rights,$email,$status)
	$usr->set_user($rw['id'],$rw['name'],$rw['fullname'],$rw2['name'],$rw['parent'],$rw['rights'].$rw2['rights'],$rw['email'],$rw['status']);
	return $usr;
  }
  
  public function doAuth()
  {
	require_once($this->site()->conf()->get('site_path')."/inc/auth.php");
	$auth=new LocalAuth();
	return $auth->render();
  }
  
  public function logout($user)
  {
    $this->site()->common_db()->queryf("UPDATE users SET active_code=NULL WHERE id=%d;",$user->id());
  }
  
}

class JEngStdServiceAuth extends JEngAuth
{
  public function __construct($site,$logger=null)
  {
    parent::__construct($site,$logger);
  }
  public function authenticate()
  {
    $uxs='somedata';
	if (isset($_COOKIE['usersess']))
    $this->site()->common_db()->queryf("");
  }
  
  public function doAuth()
  {
  }
  
  public function logout($user)
  {
  }
}

?>